home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17484 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  52 lines

  1. Newsgroups: comp.lang.c++
  2. Path: newsfeed.internetmci.com!miwok!linex1!news
  3. From: mfried@linex.com (Marty Fried)
  4. Subject: Re: Help: Bitwise operators
  5. X-Nntp-Posting-Host: sp11.linex.com
  6. Message-ID: <31730b9a.4996728@news.linex.com>
  7. Sender: news@linex1.linex.com
  8. Organization: Cirrius Cybernetics Corp
  9. X-Newsreader: Forte Agent .99e/32.209
  10. References: <4knb73$f15@wumpus.its.uow.edu.au>
  11. Date: Tue, 16 Apr 1996 02:57:33 GMT
  12.  
  13. Once upon a time (OK, it was 13 Apr 1996 14:40:03 +1000),
  14. sjl01@wumpus.its.uow.edu.au (Stuart John Langley) wrote:
  15.  
  16. >Hi All,
  17. >
  18. >I need some help understanding some code that i need to translate.
  19. >I have the following,
  20. >
  21. >unsigned char byte;
  22. >
  23. >then either - 
  24. >
  25. >byte = (byte >> 1) | 0;
  26. >
  27. >or 
  28. >
  29. >byte = (byte >> 1) | 128;
  30. >
  31. >I know that the first case places a 0 in the left most bit of byte,
  32. >and moves everything else to the right, while the second places a 1
  33. >in the leftmost bit. However, when I look at the texts and hepfiles,
  34. >this seems to indicate thet the 0 or 1 should be placed in the rightmost
  35. >bit and everything else moved left. Can somebody please help me out with
  36. >this problem>
  37.  
  38. Are you sure you know what the first one does?  It seems to me that
  39. all it does is shift right one (or divides by 2, depending on how you
  40. look at it).  ORing with zero has no effect.  ANDing with zero would
  41. force the least significant byte to be zero (right most bit).
  42.  
  43. ORing with 128 will force bit 7 to be a one.  But without knowing what
  44. you're trying to do, it's impossible to say what it should be.
  45. However, you definitely need to understand these type of operations if
  46. you want to be a programmer.
  47.  
  48. _______________________________________________________
  49. Marty Fried - mfried@linex.com     Press Enter to Exit
  50. San Anselmo, CA                           -NT message
  51. (MSVC4 + MFC) && (Win95 || NT);             
  52.